package com.demo.seckill.queue.jvm;

import com.demo.seckill.common.entity.SuccessKilled;
import com.demo.seckill.service.ISeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author libo
 * @ClassName TaskRunner
 * @Description: 消费秒杀队列
 * @date 2018/11/29 18:15
 */
//@Component
public class TaskRunner implements ApplicationRunner {

    @Autowired
    private ISeckillService seckillService;

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        while(true){
            //进程类队列
            SuccessKilled consum = SeckillQueue.getMailQueue().consum();
            if(consum !=null){
                seckillService.startSeckil(consum.getSeckillId(),consum.getUserId());
            }
        }
    }
}
